<template>
  <transition name="slide">
    <music-list :songs="songs" :title="title" :bg-image="bgImage"></music-list>
  </transition>

</template>

<script>
import {mapGetters} from 'vuex'
import { singerDetail } from '../../api/singer'
import { createSong } from '../../common/js/song'
import MusicList from '../music-list/music-list'

export default {
  name: 'singer-detail',
  components: {MusicList},
  computed: {
    ...mapGetters([
      'singer'
    ]),
    title() {
      return this.singer.name
    },
    bgImage() {
      return this.singer.avater
    }
  },
  data () {
    return {
      songs: [],
      singer_detail: {}
    }
  },
  created () {
    this._getDetail()
    this._singerDetail()
  },
  mounted () {
  },
  methods: {
    _getDetail() {
      if (!this.singer.id) {
        this.$router.push('/singer')
        return 1
      }
    },
    _singerDetail() {
      // console.log(this.$route.params.id)
      singerDetail(this.$route.params.id).then((res) => {
        if (res.code === 0) {
          // console.log(res.data.list)
          this.songs = this._normallizeSongs(res.data.list)
          // console.log(this.songs)
        }
      })
    },
    _normallizeSongs (list) {
      let ret = []
      console.log(list)
      list.forEach((item) => {
        let {musicData} = item
        if (musicData.songid && musicData.albummid) {
          ret.push(createSong(musicData))
        }
      })
      // console.log(ret)
      return ret
    }
  }
}
</script>

<style scoped lang="stylus">
  @import "~@/common/stylus/variable"
  .singer-detail
    position  fixed
    z-index 100
    top 0
    left 0
    bottom 0
    right 0
    background $color-background

  .slide-enter-active, .slide-leave-active
    transition: all 0.3s

  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)

</style>
